package com.turnengine.client.local.unit.list.count;

import java.util.ArrayList;
import java.util.List;

import com.turnengine.client.local.unit.bean.IUnit;
import com.turnengine.client.local.unit.bean.IUnitCount;
import com.turnengine.client.local.unit.bean.UnitCount;

public class UnitCountList extends ArrayList<IUnitCount> implements IUnitCountList {

	public UnitCountList() {
	}

	public UnitCountList(List<IUnitCount> list) {
		super(list);
	}

	@Override
	public long getAmount(int unitId) {
		long amount = 0;
		for (IUnitCount count : this) {
			if (count.getId() == unitId) {
				amount += count.getAmount();
			}
		}
		return amount;
	}

	@Override
	public long getAmount(IUnit unit) {
		return getAmount(unit.getId());
	}

	@Override
	public boolean contains(IUnit unit) {
		return contains(unit.getId());
	}

	@Override
	public boolean contains(int unitId) {
		for (IUnitCount count : this) {
			if (count.getId() == unitId) {
				return true;
			}
		}
		return false;
	}

	@Override
	public void add(int unitId, long amount) {
		super.add(new UnitCount(unitId, amount));
	}

	@Override
	public void add(IUnit unit, long amount) {
		add(unit.getId(), amount);
	}
}
